using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;

public class Talk : MonoBehaviour
{
    [SerializeField] private Text TxtTalk;
    [SerializeField] private Image ImgPhoto;
    [SerializeField] private Sprite[] SprPhotos;
    private bool _isOnTalk = false;

    public void ShowTalk(string msg, int photo) {
        if (_isOnTalk) { return; }

        _isOnTalk = true;
        gameObject.SetActive(true);
        TxtTalk.text = msg;
        ImgPhoto.sprite = SprPhotos[photo];
        transform.localScale = Vector3.zero;
        Sequence sequence = DOTween.Sequence();
        sequence.Append(transform.DOScale(1, 0.4f).SetEase(Ease.OutBack));
        sequence.AppendInterval(1.5f);
        sequence.Append(transform.DOScale(0, 0.15f));
        sequence.OnComplete(() => {
            gameObject.SetActive(false);
            _isOnTalk = false;
        });
    }
}
